import { createStore, applyMiddleware } from 'redux'
import { reducers } from './reducers'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
// 日志
import logger from 'redux-logger'
// 异步 action
import thunk from 'redux-thunk'
//  持久化配置
const persistConfig = {
  // 存储名称
  key: 'bw-car',
  // 使用本地存储
  storage,
  // 存储哪些仓库
  whitelist: ['cart', 'user']
}
// reducer 处理
const persistedReducer = persistReducer(persistConfig, reducers)
// 仓库
export const store = createStore(persistedReducer, /* 中间件 */applyMiddleware(logger, thunk))

// 持久化仓库
export const persistor = persistStore(store)

